<?php
define('IN_TG','post');
define('IN_JS','post');
define('SCRIPT','post');
session_start();
require('includes/common.inc.php');
require('header.php');
_check_login();
//检测是否提交
if(isset($_GET['action']))
{
	//检测提交的状态值
	if($_GET['action']=='post'){
		if($_POST['code']==$_SESSION['code']){
            include ROOT_PATH.'includes/check.func.php';
			$type = $_POST['type'];
			$title = _check_post_title($_POST['title'],2,40);
			$content = _check_post_content($_POST['content'],10);
			$username = $_SESSION['username'];
			$date = date('Y-m-d H:i:s',time());
			$userinfo=_fetch_array("select tg_post_time from tg_user where tg_username='".$username."'");
			if(time()-$userinfo['tg_post_time']>$_system['post'] )
			{
				$sql = "insert into tg_article(tg_username,tg_type,tg_title,tg_content,tg_date)values('$username','$type','$title','$content','$date')";
				$res = _query($sql);
				if($res){
					$id = _insert_id();
					_query("update tg_user set tg_post_time='".time()."' where tg_username='{$username}'");
					_location('发帖成功','article.php?id='.$id);
				}
			}
			else
			{
				_alert_back("请休息一下");
			}
		}else{
			_alert_back("验证码错误");
		}
	}
}
?>
<div id="post">
	<h2>发表帖子</h2>
	<form method="post" name="post" action="?action=post">
		<dl>
			<dt>请认真填写一下内容</dt>
			<dd>
				类　　型：
				<label for="type1">
					<input type="radio" id="type1" name="type" value="1" checked="checked" />  
					<img src="images/icon1.gif" alt="类型" /></label><label for="type2">
					<input type="radio" id="type2" name="type" value="2" />  <img src="images/icon2.gif" alt="类型" /></label><label for="type3"><input type="radio" id="type3" name="type" value="3" />  <img src="images/icon3.gif" alt="类型" /></label><label for="type4"><input type="radio" id="type4" name="type" value="4" />  <img src="images/icon4.gif" alt="类型" /></label><label for="type5"><input type="radio" id="type5" name="type" value="5" />  <img src="images/icon5.gif" alt="类型" /></label><label for="type6"><input type="radio" id="type6" name="type" value="6" />  <img src="images/icon6.gif" alt="类型" /></label><label for="type7"><input type="radio" id="type7" name="type" value="7" />  <img src="images/icon7.gif" alt="类型" /></label><label for="type8"><input type="radio" id="type8" name="type" value="8" />  <img src="images/icon8.gif" alt="类型" /></label><br />　　　 　　<label for="type9"><input type="radio" id="type9" name="type" value="9" />  <img src="images/icon9.gif" alt="类型" /></label><label for="type10"><input type="radio" id="type10" name="type" value="10" />  <img src="images/icon10.gif" alt="类型" /></label><label for="type11"><input type="radio" id="type11" name="type" value="11" />  <img src="images/icon11.gif" alt="类型" /></label><label for="type12"><input type="radio" id="type12" name="type" value="12" />  <img src="images/icon12.gif" alt="类型" /></label><label for="type13"><input type="radio" id="type13" name="type" value="13" />  <img src="images/icon13.gif" alt="类型" /></label><label for="type14"><input type="radio" id="type14" name="type" value="14" />  <img src="images/icon14.gif" alt="类型" /></label><label for="type15"><input type="radio" id="type15" name="type" value="15" />  <img src="images/icon15.gif" alt="类型" /></label><label for="type16"><input type="radio" id="type16" name="type" value="16" />  <img src="images/icon16.gif" alt="类型" /></label>			</dd>
			<dd>标　　题：<input type="text" name="title" class="text" /> (*必填，2-40位)</dd>
			<dd id="q">贴　　图：　<a href="javascript:;">Q图系列[1]</a>　 <a href="javascript:;">Q图系列[2]</a>　 <a href="javascript:;">Q图系列[3]</a></dd>
			<dd>
				<?php require("includes/ubb.inc.php");?>
				<textarea name="content" rows="9"></textarea>
			</dd>
            <dd>验 证 码：<input type="text" name="code" class="text yzm"/> <img src="code.php" id="code"
                                                                             onclick="this.src='code.php?tm='+Math.random();"/>
                <input type="submit" class="submit" value="发表帖子"/></dd>
		</dl>
	</form>
</div>
<?php
require('includes/footer.inc.php');
?>

